<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * @filename mnews.php
 * 新闻公告模型
 * @author hmw
 *
 */

class Mgames extends Model {

    function Mgames() {
        parent::Model();
    }

    /**
     * 获取游戏服务器区列表
     *
     * @param int $game_id
     * @return unknown
     */
    function get_game_areas($game_id=1,$offset=0,$limit=100){
        $this->db->limit($limit,$offset);
    	$query = $this->db->get_where('game_areas',array('game_id'=>$game_id));
    	return $query->result_array();
    }

    /**
     * 获取游戏服务器列表
     *
     * @param int $area_id
     * @return unknown
     */
    function get_game_servers($area_id=3,$offset=0,$limit=100){
        $this->db->limit($limit,$offset);
    	$query = $this->db->get_where('game_servers',array('area_id'=>$area_id));
    	return $query->result_array();
    }

    function get_area_name($area_id){
    	$query = $this->db->get_where('game_areas',array('id'=>$area_id));
    	$row = $query->row();
    	return $row ? $row->area_name : '';
    }

    function get_server_name($server_id){
    	$query = $this->db->get_where('game_servers',array('server_id'=>$server_id));
    	$row = $query->row();
    	return $row ? $row->server_name : '';
    }

    function get_game_name($game_id) {
        $query = $this->db->get_where('games',array('game_id'=>$game_id));
        $row = $query->row();
    	return $row ? $row->game_name : '';
    }

    function get_groups($game_id=1,$offset=0,$limit=100){
        $this->db->limit($limit,$offset);
        $query = $this->db->get_where('game_group',array('game_id'=>$game_id));
    	return $query->result_array();
    }

    function get_group_info($key,$value,$info){
        $query = $this->db->get_where('game_group',array($key=>$value));
    	$row = $query->row_array();
        return $row[$info];
    }

    function get_careers($game_id=1,$offset=0,$limit=100){
        $this->db->limit($limit,$offset);
        $query = $this->db->get_where('game_career',array('game_id'=>$game_id));
    	return $query->result_array();
    }

    function get_career_info($key,$value,$info){
        $query = $this->db->get_where('game_career',array($key=>$value));
    	$row = $query->row_array();
        return $row[$info];
    }

    function get_games($offset=0,$limit=10,$state=1){
        $this->db->limit($limit,$offset);
        $query = $this->db->get_where('games',array('game_state'=>$state));
    	return $query->result_array();
    }

    function get_game_count($state=1){
        $this->db->where('game_state',$state);
        return $this->db->count_all_results('games');
    }

    function insert_new_game($values){
        return $this->db->insert('games',$values);
    }

    function update_game_info($id,$values){
        return $this->db->update('games',$values,array('game_id'=>$id));
    }

    function delete_game($id){
        return $this->db->delete('games',array('game_id'=>$id));
    }

    function get_game_info($id){
        $query = $this->db->get_where('games',array('game_id'=>$id));
    	return $query->row_array();
    }

    function get_area_count($game_id){
        $this->db->where('game_id',$game_id);
        return $this->db->count_all_results('game_areas');
    }

    function get_area_info($id){
        $query = $this->db->get_where('game_areas',array('id'=>$id));
    	return $query->row_array();
    }

    function insert_new_area($values){
        return $this->db->insert('game_areas',$values);
    }

    function update_area_info($id,$values){
        return $this->db->update('game_areas',$values,array('id'=>$id));
    }

    function delete_area($id){
        return $this->db->delete('game_areas',array('id'=>$id));
    }

    function insert_new_server($values){
        return $this->db->insert('game_servers',$values);
    }

    function get_server_info($id){
        $query = $this->db->get_where('game_servers',array('server_id'=>$id));
    	return $query->row_array();
    }

    function update_server_info($id,$values){
        return $this->db->update('game_servers',$values,array('server_id'=>$id));
    }

    function delete_server($id){
        return $this->db->delete('game_servers',array('server_id'=>$id));
    }

    function get_server_count($area_id){
        $this->db->where('area_id',$area_id);
        return $this->db->count_all_results('game_servers');
    }

    function insert_new_group($values){
        return $this->db->insert('game_group',$values);
    }

    function get_group_detail($id){
        $query = $this->db->get_where('game_group',array('group_id'=>$id));
    	return $query->row_array();
    }

    function get_group_count($game_id){
        $this->db->where('game_id',$game_id);
        return $this->db->count_all_results('game_group');
    }

    function update_group_info($group_id,$values){
        return $this->db->update('game_group',$values,array('group_id'=>$group_id));
    }

    function delete_group($id){
        return $this->db->delete('game_group',array('group_id'=>$id));
    }

    function insert_new_career($values){
        return $this->db->insert('game_career',$values);
    }

    function get_career_detail($id){
        $query = $this->db->get_where('game_career',array('career_id'=>$id));
    	return $query->row_array();
    }

    function get_career_count($game_id){
        $this->db->where('game_id',$game_id);
        return $this->db->count_all_results('game_career');
    }

    function update_career_info($career_id,$values){
        return $this->db->update('game_career',$values,array('career_id'=>$career_id));
    }

    function delete_career($id){
        return $this->db->delete('game_career',array('career_id'=>$id));
    }

}

?>